package cn.alpha.intell.rbtlib.utils;

import android.content.Context;
import android.os.Handler;
import android.widget.Toast;

/**
 * Created by white on 15/7/15.
 *
 * @description 直接在主进程显示的Toast，不需要再特地在主线程中弹出了
 */
public class ToastUtil {

    public static void showShortToast(final Context context, final String text) {
        new Handler(context.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
            }
        });
    }

    public static void showLongToast(final Context context, final String text) {
        new Handler(context.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(context, text, Toast.LENGTH_LONG).show();
            }
        });
    }

    public static void showShortToast(final Context context, final int resId) {
        new Handler(context.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
            }
        });
    }

    public static void showLongToast(final Context context, final int resId) {
        new Handler(context.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(context, resId, Toast.LENGTH_LONG).show();
            }
        });
    }

    public static void show(Context context, int resId) {
        try {
            show(context, context.getResources().getText(resId), Toast.LENGTH_SHORT);
        } catch (Exception e) {
        }

    }

    public static void show(Context context, int resId, int duration) {
        try {
            show(context, context.getResources().getText(resId), duration);
        } catch (Exception e) {
        }
    }

    public static void show(Context context, CharSequence text) {
        try {
            show(context, text, Toast.LENGTH_SHORT);
        } catch (Exception e) {
        }
    }

    public static void show(Context context, CharSequence text, int duration) {
        Toast.makeText(context, text, duration).show();
    }

    public static void show(CharSequence text, int duration) {
        show(ContextFinder.getApplication(), text, duration);
    }

    public static void show(CharSequence text) {
        show(text, Toast.LENGTH_SHORT);
    }


}
